#ifndef CONSOLE_H
#define CONSOLE_H
typedef enum
{
    CONSOLE_CMD_CALL,
    CONSOLE_CMD_HELP
}console_cmd_t;

enum
{
    CONSOLE_IOCTL_NOTHING = 0,
    CONSOLE_IOCTL_GET_ECHO_STATUS,
    CONSOLE_IOCTL_SET_ECHO_STATUS,
    CONSOLE_IOCTL_GET_RAW_MODE_STATUS,
    CONSOLE_IOCTL_SET_RAW_MODE_STATUS,
    CONSOLE_IOCTL_GET_INPUT_ENABLE,
    CONSOLE_IOCTL_SET_INPUT_ENABLE,
};
typedef int (*command_handler_t)(console_cmd_t cmd, const char*param);

typedef struct
{
    command_handler_t handler;
    const char *exec;
    const char *help_info;
    char reserver[4]; // padding to 16Bytes Align
}console_exec_handler_t;

#define CONSOLE_COMMAND_HANDLER(name) static int name(console_cmd_t cmd, const char *param)

#define CONSOLE_EXEC_REGISTER(_handler, _exec_name, _help_info) \
const console_exec_handler_t console_exec_##_handler __attribute__((section(".console_exec")))= {.handler = _handler, .exec = _exec_name, .help_info = _help_info}

#define CONSOLE_COMMAND_PARAM_FOREACH_BEGIN(iterator, src_str) \
{\
    const char *__cmd_buf = src_str; \
    do { \
        __cmd_buf = console_get_word(__cmd_buf, iterator);

#define CONSOLE_COMMAND_PARAM_FOREACH_END(iterator, src_str) \
    }while(__cmd_buf != NULL); \
}

#define console_exec_handler_foreach(iterator) for(const console_exec_handler_t *iterator = __console_exec_start; iterator<__console_exec_end; iterator++)

char *console_get_word(const char* src, char* dst);
int console_thread_handler(void *args);
int console_ioctl(int ioctl, int* param);
#endif
